package thu.infinity.facebook;

import thu.infinity.commons.AggregatorHandler;
import thu.infinity.commons.Task;
import thu.infinity.thrift.Constants;
import thu.infinity.thrift.PhotoEntry;

public class CachePhotoTask extends Task {
	int type;
	PhotoEntry photoEnt;
	
	public CachePhotoTask(PhotoEntry photoEnt, int type, AggregatorHandler handler) {
		this.type = type;
		this.photoEnt = photoEnt;
		this.handler = handler;
	}
	@Override
	public void execute() {
		// TODO Auto-generated method stub
		String sourceFn = (type == Constants.PhotoEntryTypePhoto) ? Util.photoName(photoEnt.id) : Util.videoName(photoEnt.id);
		FacebookUtil.cachePhoto(photoEnt.source, sourceFn);
		photoEnt.photoSize = Util.newFile(sourceFn).length();
		String thumbFn = Util.photoThumbName(photoEnt.id);
		FacebookUtil.cachePhoto(photoEnt.picture, thumbFn);
		photoEnt.thumbSize = Util.newFile(thumbFn).length();
	}

	@Override
	public boolean checkCondition() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	protected Task genNextTask() {
		// TODO Auto-generated method stub
		return null;
	}

}
